﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EasyFramework.System
{
    public class DateTimeHelper
    {

        /// <summary>
        /// 版权：广联达软件股份有限公司
        /// 创建：战东耀, 2012-04-13
        /// 说明: 获取指定日期所在的周
        /// 修改: 
        /// </summary>
        /// <param name="theDate">指定的日期</param>
        /// <param name="startDate">周一</param>
        /// <param name="endDate">周日</param>
        public static void GetDateByWeek(DateTime theDate, ref DateTime startDate, ref DateTime endDate)
        {
            if (null == theDate || theDate == DateTime.MinValue || theDate == DateTime.MaxValue)
            {
                theDate = DateTime.Now;
            }

            int dayOfWeek = theDate.DayOfWeek == DayOfWeek.Sunday ? 7 : (int)theDate.DayOfWeek;
            startDate = theDate.Date.AddDays(1 - dayOfWeek);
            endDate = theDate.Date.AddDays(7 - dayOfWeek);
        }
    }
}
